package com.gxa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.gxa.common.base.RespResult;
import com.gxa.domain.dto.CablePlanDto;
import com.gxa.domain.entity.CablePlan;
import com.gxa.mapper.CablePlanMapper;
import com.gxa.service.CablePlanService;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 实现类
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class CablePlanServiceImpl extends ServiceImpl<CablePlanMapper, CablePlan> implements CablePlanService {
    @Autowired
    private CablePlanMapper cablePlanMapper;

    /**
     * 分页查询
     *
     * @param cablePlanDto
     * @return
     */
    @Override
    public RespResult pagequery(CablePlanDto cablePlanDto) {
        PageHelper.startPage(cablePlanDto.getPage(), cablePlanDto.getPageSize());
        List<CablePlan> cablePlans = cablePlanMapper.pagequery(cablePlanDto);
        return RespResult.success(cablePlans);
    }

//    @Override
//    public Workbook generateExcel() {
//        List<CablePlan> cablePlans = cablePlanMapper.selectAll();
//        Workbook workbook = new XSSFWorkbook();
//        Sheet sheet = workbook.createSheet();
//        Row headerRow = sheet.createRow(0);
//        headerRow.createCell(0).setCellValue("项目编号");
//        headerRow.createCell(1).setCellValue("项目名称");
//        headerRow.createCell(2).setCellValue("电缆名称");
//        headerRow.createCell(3).setCellValue("电压等级");
//        headerRow.createCell(4).setCellValue("电缆截面");
//        headerRow.createCell(5).setCellValue("抽取时间");
//        headerRow.createCell(6).setCellValue("入库状态");
//        headerRow.createCell(7).setCellValue("入库数量");
//        headerRow.createCell(8).setCellValue("出库状态");
//        headerRow.createCell(9).setCellValue("出库数量");
//        headerRow.createCell(10).setCellValue("派单状态");
//        headerRow.createCell(11).setCellValue("计划状态");
//        int rowNum = 1;
//        for (CablePlan cablePlan : cablePlans) {
//            Row row = sheet.createRow(rowNum++);
//            row.createCell(0).setCellValue(cablePlan.getProjectId());
//            row.createCell(1).setCellValue(cablePlan.getProjectName());
//            row.createCell(2).setCellValue(cablePlan.getCableName());
//            row.createCell(3).setCellValue(cablePlan.getVoltageName());
//            row.createCell(4).setCellValue(cablePlan.getExtractionLength());
//            row.createCell(5).setCellValue(cablePlan.getExtractionDate());
//            row.createCell(6).setCellValue(cablePlan.getReceivingStatus());
//            row.createCell(7).setCellValue(cablePlan.getReceivingNumber());
//            row.createCell(8).setCellValue(cablePlan.getShippingStatus());
//            row.createCell(9).setCellValue(cablePlan.getShippingNumber());
//            row.createCell(10).setCellValue(cablePlan.getDispatchStatus());
//            row.createCell(11).setCellValue(cablePlan.getPlanStatus());
//        }
//        return workbook;
//    }
}
